package com.outsourcing.bottle.ui.fragment;

import java.util.List;

import org.json.JSONObject;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.outsourcing.bottle.BasicActivity;
import com.outsourcing.bottle.R;
import com.outsourcing.bottle.SplashActivity;
import com.outsourcing.bottle.adapter.PublicActivityAdapter;
import com.outsourcing.bottle.adapter.PublicActivityAdapter.ViewHolder;
import com.outsourcing.bottle.db.BottleTypeTable;
import com.outsourcing.bottle.db.LanguageConfigTable;
import com.outsourcing.bottle.db.LoginUserInfoTable;
import com.outsourcing.bottle.db.PushNoticeInfoTable;
import com.outsourcing.bottle.db.StickersPackTable;
import com.outsourcing.bottle.domain.BottleEntry;
import com.outsourcing.bottle.domain.BottleTimelineInfo;
import com.outsourcing.bottle.domain.BottleTypeEntry;
import com.outsourcing.bottle.domain.LanguageConfig;
import com.outsourcing.bottle.domain.LoginUserInfo;
import com.outsourcing.bottle.domain.LoginUserInfoEntry;
import com.outsourcing.bottle.domain.PasterDirConfigEntry;
import com.outsourcing.bottle.domain.PushNoticeInfo;
import com.outsourcing.bottle.domain.UrlConfig;
import com.outsourcing.bottle.remoteimage.RemoteImageView;
import com.outsourcing.bottle.ui.ChooseBottleActivity;
import com.outsourcing.bottle.ui.ChooseLocationTabsActivity;
import com.outsourcing.bottle.ui.HomeActivity;
import com.outsourcing.bottle.ui.SettingActivity;
import com.outsourcing.bottle.ui.ThrowBottleSettingActivity;
import com.outsourcing.bottle.util.AppContext;
import com.outsourcing.bottle.util.BasicUIEvent;
import com.outsourcing.bottle.util.HttpUtils;
import com.outsourcing.bottle.util.ServiceUtils;
import com.outsourcing.bottle.util.TextUtil;
import com.outsourcing.bottle.util.UICore;
import com.outsourcing.bottle.widget.CustomListView;
import com.outsourcing.bottle.widget.CustomPopupWindow;

/**
 * 
 * @author 06peng
 * 
 */
public class BottleFragment extends Fragment implements BasicUIEvent, Callback,
		OnClickListener, OnScrollListener {

	private static final String TAG = BottleFragment.class.getSimpleName();

	public HomeActivity activity;

	private View mLikeView = null;
	private CustomPopupWindow mLikePopview = null;

	public static final int EXEU_GET_TIMELINE = 0;
	private static final int EXEU_LIKE_OPERATION = 1;
	private static final int EXEU_UNLIKE_OPERATION = 2;
	private static final int EXEU_OPEN_BOTTLE_OPERATION = 3;
	private static final int EXEU_OPEN_BOTTLE_SUCCESS = 4;
	private static final int EXEU_OPEN_BOTTLE_FAILED = 5;
	private static final int EXEU_DROP_BOTTLE_OPERATION = 6;
	private static final int EXEU_DROP_BOTTLE_SUCCESS = 7;
	private static final int EXEU_DROP_BOTTLE_FAILED = 8;
	private static final int EXEU_SEND_BOTTLE_PRIV_SUCCESS = 9;
	private static final int EXEU_SEND_BOTTLE_PRIV_SUCCESS_NOT_ENABLE = 10;
	private static final int EXEU_SEND_BOTTLE_PRIV_FAILED = 11;
	private static final int EXEU_GET_BOTTLE_PRIV_OPERATION = 12;
	private static final int EXEU_LIKE_OPERATION_FAILED = 13;
	private static final int EXEU_GET_MORE_TIMELINE = 15;
	private static final int EXEU_GET_BOTTLE_INFO = 16;
	private static final int EXEU_GET_TIMELINE_FAILED = 17;
	private static final int EXEU_REFRESH_TIMELINE = 18;
	private static final int EXEU_GET_MORE_TIMELINE_NOTHING = 19;

	private static final int EXEU_GET_MENU_TIMELINE = 20;
	private static final int EXEU_GET_SINGLE_BOTTLE_SUCCESS = 21;

	private final int refresh_bottle_fragment = 22;
	private final int throw_bottle_init_location = 23;
	private static final int EXEU_SET_BTPIC_PAINT = 24;
	private static final int EXEU_PASTERDIR_PAY = 25;
	private static final int EXEU_PUSH_NOTICE = 26;
	
	private CustomListView listView;
	private View mheaderView = null;
	private View loadMoreView = null;
	private Handler handler = null;
	private PublicActivityAdapter mTimeLineAdapter;
	private BottleTimelineInfo bottlelist = null;
	private List<BottleEntry> mBottleList = null;
	public int btId = -1;
	private int btTypeId;
	private int page = 1;
	private int mode = 0;
	public boolean init = false;

	private int visibleLastIndex = 0; // 最后的可视项索引
	private int visibleItemCount; // 当前窗口可见项总数

	LinearLayout contentView = null;
	
	private StickersPackTable stickPackTable;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ServiceUtils.dout(TAG + "onCreate");
		setRetainInstance(true);
		activity = (HomeActivity) getActivity();
		handler = new Handler(this);
//		if (AppContext.getInstance().getCurrentItem() == 1) {
//			doGetBottleTimeline();
//		}
		doGetBottleTimeline();
		AppContext.setContext(activity);
		stickPackTable = new StickersPackTable();
	}

	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		ServiceUtils.dout(TAG + "onCreateView");
		View view = inflater.inflate(R.layout.bottle_fragment, null);

		listView = (CustomListView) view.findViewById(R.id.list_view);
		listView.setonRefreshListener(new CustomListView.OnRefreshListener() {
			
			@Override
			public void onRefresh() {
				refresh();
			}
		});
		loadMoreView = inflater.inflate(R.layout.refreshable_list_footer, null);
		loadMoreView.setVisibility(View.GONE);
		mheaderView = LayoutInflater.from(activity).inflate(
				R.layout.bottle_list_header, null);
		listView.addHeaderView(mheaderView);
		listView.addFooterView(loadMoreView);
		listView.setOnScrollListener(this); // 添加滑动监听

		initLikePopupWindow();
		return view;
	}

	public void doGetBottleTimeline() {
		if (!init) {
			UICore.eventTask(this, activity, EXEU_GET_TIMELINE, "EXEU_GET_TIMELINE", null);
		}
	}
	
	public void doGetBottleTimeline_Refresh() {
		UICore.eventTask(this, activity, refresh_bottle_fragment, "refresh_bottle_fragment", null);
	}

	@Override
	public void onResume() {
		super.onResume();
		ServiceUtils.dout(TAG + "onResume");
		handler = new Handler(this);
		if (AppContext.getInstance().isFromBottleTime()) {
			AppContext.getInstance().setFromBottleTime(false);
			UICore.eventTask(this, activity, EXEU_REFRESH_TIMELINE,
					"EXEU_GET_TIMELINE", null);
		}
	}

	@Override
	public void execute(int mes, Object obj) {
		switch (mes) {
		case EXEU_GET_TIMELINE:
			if (!init) {
				getLoginUserInfo();
				getTimeLineForRefresh(mode);
				init = true;
			}
			break;
		case EXEU_REFRESH_TIMELINE:
			getSingleBottle(btId);
			break;
		case refresh_bottle_fragment:
			getLoginUserInfo();
			getTimeLineForRefresh(mode);
			break;
		case EXEU_GET_MORE_TIMELINE:
			getMoreTimeLine(page, mode);
			break;
		case EXEU_LIKE_OPERATION:
			likeOperation(btId, 1);
			break;
		case EXEU_UNLIKE_OPERATION:
			likeOperation(btId, 2);
			break;
		case EXEU_OPEN_BOTTLE_OPERATION:
			openBottle(btId);
			break;
		case EXEU_DROP_BOTTLE_OPERATION:
			dropBottle(btId);
			break;
		case EXEU_GET_BOTTLE_PRIV_OPERATION:
			getSendSingleBtPriv(btTypeId, btId);
			break;
		case EXEU_GET_MENU_TIMELINE:
			getTimeLine(mode);
			break;
		case EXEU_GET_SINGLE_BOTTLE_SUCCESS:
			getSingleBottle(btId);
			break;
		case throw_bottle_init_location:
			Object idObj = obj;
			((BasicActivity) getActivity()).networkLocat();
			Message msg = Message.obtain(handler, throw_bottle_init_location, idObj);
			handler.sendMessage(msg);
			break;
		case EXEU_SET_BTPIC_PAINT:
			int optype = (Integer)obj;
			setBtpicPaint(btId, optype);
			break;
		default:
			break;
		}
	}
	
	private void getPushNotice() {
		StringBuffer url = new StringBuffer(UrlConfig.push_notice);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		try {
			String result = HttpUtils.doGet(url.toString());
			if (result != null) {
				JSONObject obj = new JSONObject(result);
				JSONObject resultObj = obj.getJSONObject("results");
				if (resultObj.getInt("authok") == 1) {
					JSONObject pushObj = obj.getJSONObject("push_notice");
					PushNoticeInfoTable table = new PushNoticeInfoTable();
					PushNoticeInfo pushInfo = new PushNoticeInfo();
					table.clearTable();
					pushInfo.setMessage_avatar(pushObj.getString("message_avatar"));
					pushInfo.setMessage_content(pushObj.getString("message_content"));
					pushInfo.setNew_btfeed_count(pushObj.getInt("new_btfeed_count"));
					pushInfo.setNew_exfeed_count(pushObj.getInt("new_exfeed_count"));
					pushInfo.setNew_message_count(pushObj.getInt("new_message_count"));
					pushInfo.setNew_notice_count(pushObj.getInt("new_notice_count"));
					table.savePushNoticeInfo(pushInfo, AppContext.getInstance().getLogin_uid());
					
					Message message = Message.obtain(handler);
					message.what = EXEU_PUSH_NOTICE;
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void refresh() {
		page = 1;
		new Thread() {
			public void run() {
				getLoginUserInfo();
				getTimeLineForRefresh(mode);
				handler.sendEmptyMessage(EXEU_GET_TIMELINE);
			};
		}.start();
	}
	
	/**
	 * 获取用户基本资料
	 */
	private void getLoginUserInfo() {
		StringBuffer url = new StringBuffer(UrlConfig.get_loginuser_info);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		ServiceUtils.dout("login url:" + url.toString());
		try {
			String result = HttpUtils.doGet(url.toString());
			Gson gson = new Gson();
			LoginUserInfo loginUserInfo = gson.fromJson(result,
					LoginUserInfo.class);
			LoginUserInfoTable loginUserInfoTable = new LoginUserInfoTable();
			if (null != loginUserInfoTable.getLoginUserInfo(AppContext
					.getInstance().getLogin_uid())) {
				String net_avatar = loginUserInfo.getLoginuser_info()
						.getAvatar();
				String old_avatar = loginUserInfoTable.getLoginUserInfo(
						AppContext.getInstance().getLogin_uid()).getAvatar();
//				if (!TextUtils.isEmpty(net_avatar)) {
//					ServiceUtils.downLoadImage(net_avatar, AppContext.UserAvatarIcon);
//				}
				loginUserInfoTable.deleteLoginUserInfoById(AppContext
						.getInstance().getLogin_uid());
				loginUserInfoTable.saveLoginUserInfo(loginUserInfo
						.getLoginuser_info(), AppContext.getInstance()
						.getLogin_uid());
				/***********保存贴纸目录路径*********/
				List<PasterDirConfigEntry> pasterdir_config = loginUserInfo.getPasterdir_privs_list();
				stickPackTable.clearTalbe();
				for (PasterDirConfigEntry mPasterDirEntry : pasterdir_config) {
//					ServiceUtils.downLoadImage(mPasterDirEntry.getPasterdir_coverurl(),mPasterDirEntry.getPasterdir_id()+"",
//							AppContext.PasterDir);
					stickPackTable.saveStickDir(mPasterDirEntry);
				}
			} else {
				loginUserInfoTable.saveLoginUserInfo(loginUserInfo
						.getLoginuser_info(), AppContext.getInstance()
						.getLogin_uid());
				
				/***********保存贴纸目录路径*********/
				List<PasterDirConfigEntry> pasterdir_config = loginUserInfo.getPasterdir_privs_list();
				stickPackTable.clearTalbe();
				for (PasterDirConfigEntry mPasterDirEntry : pasterdir_config) {
//					ServiceUtils.downLoadImage(mPasterDirEntry.getPasterdir_coverurl(),mPasterDirEntry.getPasterdir_id()+"",
//							AppContext.PasterDir);
					stickPackTable.saveStickDir(mPasterDirEntry);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void doSendSingleBtPri(int btTypeId, int btId) {
		this.btId = btId;
		this.btTypeId = btTypeId;
		UICore.eventTask(this, activity, EXEU_GET_BOTTLE_PRIV_OPERATION, "", null);
	}

	/** 获取扔瓶子的权限 */
	public void getSendSingleBtPriv(int btTypeId, int btId) {
		StringBuffer url = new StringBuffer(UrlConfig.get_sendsinglebt_priv);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&bttypeid=" + btTypeId);
		ServiceUtils.dout("sendsingleBT private url:" + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("getsendsinglebt_priv result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int authok = resultObj.getInt("authok");
				String errmsg = resultObj.getString("errmsg");

				if (authok == 1) {
					JSONObject privObj = obj.getJSONObject("sendsinglebt_priv");
					int enable = privObj.getInt("enable");
					String reason = privObj.getString("reason");

					if (enable == 1) {
						Bundle bundle = new Bundle();
						bundle.putInt("type", btTypeId);
						bundle.putInt("btid", btId);
						bundle.putString("reason", reason);
						Message message = handler.obtainMessage(EXEU_SEND_BOTTLE_PRIV_SUCCESS);
						message.setData(bundle);
						handler.sendMessage(message);
					} else {
						Message message = handler.obtainMessage(EXEU_SEND_BOTTLE_PRIV_SUCCESS_NOT_ENABLE, reason);
						handler.sendMessage(message);
					}

				} else {
					Message message = handler.obtainMessage(
							EXEU_SEND_BOTTLE_PRIV_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	/**
	 * 
	 * @param objtype 要清除的位置的类型：选择项：（1）瓶子动态的位置信息、（2）交换动态留言的位置信息、（3）照片评论的位置信息、（4）私信的位置信息、（5）照片的位置信息
	 * @param objid objid
	 */
	private void deleteLocation(int objtype,int objid) {
		StringBuffer url = new StringBuffer(UrlConfig.delete_location);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&objtype=" + objtype);
		url.append("&objid=" + objid);
		ServiceUtils.dout("deleteLocation url:" + url.toString());
		try {
			String result = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("deleteLocation result:" + result);
			Gson gson = new Gson();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void doPicPaint(int btid,int optype){
		this.btId = btid;
		UICore.eventTask(this, activity, EXEU_SET_BTPIC_PAINT, "", optype);
	}
	
	/**
	 * 设置瓶子照片涂鸦权限接口
	 * @param btid 瓶子ID
	 * @param optype 设置是否允许涂鸦。选择项：不允许（0）、允许（1）
	 */
	private void setBtpicPaint(int btid,int optype) {
		this.btId = btid;
		StringBuffer url = new StringBuffer(UrlConfig.set_btpic_paint);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&btid=" + btid);
		url.append("&optype=" + optype);
		ServiceUtils.dout("setBtpicPaint url:" + url.toString());
		try {
			String result = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("setBtpicPaint result:" + result);
			if (result != null) {
				JSONObject object = new JSONObject(result);
				JSONObject resultObj = object.getJSONObject("results");
				int authok = resultObj.getInt("success");
				if (authok == 0) {
					String errmsg = resultObj.getString("errmsg");
					Message msg = Message.obtain(handler, EXEU_GET_TIMELINE_FAILED, errmsg);
					handler.sendMessage(msg);
				} else {
					String successmsg = resultObj.getString("successmsg");
					Message msg = Message.obtain(handler, EXEU_SET_BTPIC_PAINT, successmsg);
					handler.sendMessage(msg);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	

	private void getTimeLine(int mode) {
		if (AppContext.getInstance().getLogin_uid() == 0
				|| AppContext.getInstance().getLogin_token() == null) {
			initConfig();
		}

		StringBuffer url = new StringBuffer(UrlConfig.get_bt_timeline);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&mode=" + mode);
		url.append("&count=10");
		url.append("&page=1");
		url.append("&likescount=5");
		url.append("&feedscount=5");
		ServiceUtils.dout("timeline url:" + url.toString());

		try {
			String result = HttpUtils.doGet(url.toString());

			if (result == null) {
				return;
			}
			System.out.println("result:" + result);
			Gson gson = new Gson();
			bottlelist = gson.fromJson(result, BottleTimelineInfo.class);
			if (bottlelist.getResults().getAuthok() == 1) {
				mBottleList = bottlelist.getBts_list();
				Message message = Message.obtain(handler);
				message.what = EXEU_GET_TIMELINE;
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_GET_TIMELINE_FAILED, bottlelist.getResults()
								.getErrmsg());
				handler.sendMessage(message);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void getTimeLineForRefresh(int mode) {
		if (AppContext.getInstance().getLogin_uid() == 0
				|| AppContext.getInstance().getLogin_token() == null) {
			initConfig();
		}

		StringBuffer url = new StringBuffer(UrlConfig.get_bt_timeline);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&mode=" + mode);
		url.append("&count=10");
		url.append("&page=1");
		url.append("&likescount=5");
		url.append("&feedscount=5");
		ServiceUtils.dout("timeline url:" + url.toString());

		try {
			String result = HttpUtils.doGet(url.toString());

			if (result == null) {
				return;
			}
			System.out.println("result:" + result);
			Gson gson = new Gson();
			bottlelist = gson.fromJson(result, BottleTimelineInfo.class);
			if (bottlelist.getResults().getAuthok() == 1) {
				mBottleList = bottlelist.getBts_list();
				handler.sendEmptyMessage(EXEU_GET_TIMELINE);
			} else {
				Message message = handler.obtainMessage(EXEU_GET_TIMELINE_FAILED, bottlelist.getResults().getErrmsg());
				handler.sendMessage(message);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void getMoreTimeLine(int page, int mode) {
		StringBuffer url = new StringBuffer(UrlConfig.get_bt_timeline);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&mode=" + mode);
		url.append("&count=10");
		url.append("&page=" + page);
		url.append("&likescount=10");
		url.append("&feedscount=5");
		ServiceUtils.dout("timeline url:" + url.toString());

		try {
			String result = HttpUtils.doGet(url.toString());
			if (result == null) {
				return;
			}
			System.out.println("result:" + result);
			Gson gson = new Gson();
			bottlelist = null;
			bottlelist = gson.fromJson(result, BottleTimelineInfo.class);
			Message message = null;
			if (bottlelist.getResults().getAuthok() == 1) {
				if (null != bottlelist.getBts_list()
						&& bottlelist.getBts_list().size() > 0) {
					mBottleList.addAll(bottlelist.getBts_list());
					message = Message.obtain(handler);
					message.what = EXEU_GET_MORE_TIMELINE;
					handler.sendMessage(message);
				} else {
					message = Message.obtain(handler);
					message.what = EXEU_GET_MORE_TIMELINE_NOTHING;
					handler.sendMessage(message);
				}
			} else {
				message = handler.obtainMessage(EXEU_GET_TIMELINE_FAILED,
						bottlelist.getResults().getErrmsg());
				handler.sendMessage(message);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void setAdapterForThis() {
		if (null != bottlelist) {
			LanguageConfigTable languageConfigTable = new LanguageConfigTable();
			LanguageConfig languageCon = languageConfigTable.getBottleLanguageConfig();

			RelativeLayout mProfileInfo = (RelativeLayout) mheaderView
					.findViewById(R.id.rl_tlime_profile_bottle);
			View line_profile_bottle = (View)mheaderView.findViewById(R.id.line_profile_bottle);
			
			RelativeLayout mThrowBottle = (RelativeLayout) mheaderView
					.findViewById(R.id.rl_tlime_throw_bottle);
			View line_throw_bottle = (View)mheaderView.findViewById(R.id.line_throw_bottle);
			RelativeLayout mGainBottle = (RelativeLayout) mheaderView
					.findViewById(R.id.rl_tlime_gain_bottle);
			View line_gain_bottle = (View)mheaderView.findViewById(R.id.line_gain_bottle);
			LoginUserInfoTable loginUserInfoTable = new LoginUserInfoTable();
			LoginUserInfoEntry loginUserInfoEntry = loginUserInfoTable
					.getLoginUserInfo(AppContext.getInstance().getLogin_uid());

			if (null != loginUserInfoEntry
					&& loginUserInfoEntry.getBasicinfo_fullfill() == 0) {
				mProfileInfo.setVisibility(View.VISIBLE);
				line_profile_bottle.setVisibility(View.VISIBLE);
				RemoteImageView img_head = (RemoteImageView) mheaderView
						.findViewById(R.id.iv_author_photo);

				LoginUserInfoTable userInfoTable = new LoginUserInfoTable();
				if (null != userInfoTable.getLoginUserInfo(AppContext
						.getInstance().getLogin_uid())) {
					String avatar = userInfoTable.getLoginUserInfo(
							AppContext.getInstance().getLogin_uid())
							.getAvatar();
					if (!TextUtils.isEmpty(avatar)) {
						img_head.setDefaultImage(R.drawable.avatar_default_small);
						img_head.setImageUrl(avatar);
					}
				}
				ImageView img_Profile = (ImageView) mheaderView
						.findViewById(R.id.iv_profile_info);
				img_Profile.setOnClickListener(this);
				TextView tvProfileTips = (TextView) mheaderView
						.findViewById(R.id.tv_bottle_profile_tips_2);
				tvProfileTips.setText(loginUserInfoEntry.getBasicinfo_tip());
				Button bt_profile = (Button) mheaderView
						.findViewById(R.id.bt_bottle_profile_try);
				bt_profile.setOnClickListener(this);
			} else {
				mProfileInfo.setVisibility(View.GONE);
				line_profile_bottle.setVisibility(View.GONE);
			}

			if (bottlelist.getShowtips().getShow_sendbt_tips() == 1) {
				mThrowBottle.setVisibility(View.VISIBLE);
				line_throw_bottle.setVisibility(View.VISIBLE);
				RemoteImageView img_head = (RemoteImageView) mheaderView
						.findViewById(R.id.iv_throw_author_photo);

				if (null != loginUserInfoTable.getLoginUserInfo(AppContext
						.getInstance().getLogin_uid())) {
					String avatar = loginUserInfoTable.getLoginUserInfo(
							AppContext.getInstance().getLogin_uid())
							.getAvatar();
					if (!TextUtils.isEmpty(avatar)) {
						img_head.setDefaultImage(R.drawable.avatar_default_small);
						img_head.setImageUrl(avatar);
					}
				}
				
				String bottleThrowTips1 = null;
				String bottleThrowTips2 = null;
				if (AppContext.language == 1) {
					bottleThrowTips1 = languageCon.getBottle_throw_tips_cn();
					bottleThrowTips2 = languageCon.getBottle_throw_tips_2_cn();
				}else {
					bottleThrowTips1 = languageCon.getBottle_throw_tips_en();
					bottleThrowTips2 = languageCon.getBottle_throw_tips_2_en();
				}
				TextView tvThrowTips = (TextView) mheaderView
						.findViewById(R.id.tv_bottle_throw_tips);
				tvThrowTips.setText(bottleThrowTips1);
				TextView tvThrowTip2 = (TextView) mheaderView
						.findViewById(R.id.tv_bottle_throw_tips_2);
				tvThrowTip2.setText(bottleThrowTips2);
				ImageView img_Throw = (ImageView) mheaderView.findViewById(R.id.iv_send_bottle);
				img_Throw.setOnClickListener(this);
				Button bt_throw = (Button) mheaderView.findViewById(R.id.bt_bottle_throw_try);
				bt_throw.setOnClickListener(this);
			} else {
				mThrowBottle.setVisibility(View.GONE);
				line_throw_bottle.setVisibility(View.GONE);
			}
			if (bottlelist.getShowtips().getShow_gainbt_tips() == 1) {
				mGainBottle.setVisibility(View.VISIBLE);
				line_gain_bottle.setVisibility(View.VISIBLE);
				RemoteImageView img_head = (RemoteImageView) mheaderView
						.findViewById(R.id.iv_gain_author_photo);
				if (null != loginUserInfoTable.getLoginUserInfo(AppContext
						.getInstance().getLogin_uid())) {
					String avatar = loginUserInfoTable.getLoginUserInfo(
							AppContext.getInstance().getLogin_uid()).getAvatar();
					if (!TextUtils.isEmpty(avatar)) {
						img_head.setDefaultImage(R.drawable.avatar_default_small);
						img_head.setImageUrl(avatar);
					}
				}
				String bottleGainTips1 = null;
				String bottleGainTips2 = null;
				if (AppContext.language == 1) {
					bottleGainTips1 = languageCon.getBottle_gain_tips_cn();
					bottleGainTips2 = languageCon.getBottle_gain_tips_2_cn();
				}else {
					bottleGainTips1 = languageCon.getBottle_gain_tips_en();
					bottleGainTips2 = languageCon.getBottle_gain_tips_2_en();
				}
				TextView tvGainTips = (TextView) mheaderView
						.findViewById(R.id.tv_bottle_gain_tips);
				tvGainTips.setText(bottleGainTips1);
				TextView tvGainTip2 = (TextView) mheaderView
						.findViewById(R.id.tv_bottle_gain_tips_2);
				tvGainTip2.setText(bottleGainTips2);
				
				ImageView img_Gain = (ImageView) mheaderView
						.findViewById(R.id.iv_gain_bottle);
				img_Gain.setOnClickListener(this);
				Button bt_gain = (Button) mheaderView
						.findViewById(R.id.bt_bottle_gain_try);
				bt_gain.setOnClickListener(this);

			} else {
				mGainBottle.setVisibility(View.GONE);
				line_gain_bottle.setVisibility(View.GONE);
			}

			
			if (mProfileInfo.getVisibility() == View.VISIBLE && mThrowBottle.getVisibility() == View.VISIBLE && mGainBottle.getVisibility() == View.VISIBLE ) {
				line_gain_bottle.setVisibility(View.GONE);
			}else if (mProfileInfo.getVisibility() == View.VISIBLE && mThrowBottle.getVisibility() == View.VISIBLE && mGainBottle.getVisibility() == View.GONE) {
				line_throw_bottle.setVisibility(View.GONE);
			} else if (mProfileInfo.getVisibility() == View.VISIBLE && mThrowBottle.getVisibility() == View.GONE && mGainBottle.getVisibility() == View.GONE) {
				line_profile_bottle.setVisibility(View.GONE);
			} else if (mProfileInfo.getVisibility() == View.GONE && mThrowBottle.getVisibility() == View.VISIBLE && mGainBottle.getVisibility() == View.VISIBLE) {
				line_gain_bottle.setVisibility(View.GONE);
			} else if (mProfileInfo.getVisibility() == View.GONE && mThrowBottle.getVisibility() == View.VISIBLE && mGainBottle.getVisibility() == View.GONE) {
				line_throw_bottle.setVisibility(View.GONE);
			} else if (mProfileInfo.getVisibility() == View.GONE && mThrowBottle.getVisibility() == View.GONE && mGainBottle.getVisibility() == View.VISIBLE) {
				line_gain_bottle.setVisibility(View.GONE);
			}
			
			// listView.addFooterView(v);
			// if
			// (mProfileInfo.getVisibility()==View.VISIBLE||mThrowBottle.getVisibility()==View.VISIBLE||mGainBottle.getVisibility()==View.VISIBLE)
			// {
			// chatHistoryAdapter = new PublicActivityAdapter(activity,this,
			// bottlelist,true);
			// }else {
			mTimeLineAdapter = new PublicActivityAdapter(activity, this,
					mBottleList, false);
			// }
			listView.setAdapter(mTimeLineAdapter);
		}

	}

	/** 喜欢pop */
	private void initLikePopupWindow() {

		LayoutInflater mLayoutInflater = LayoutInflater.from(activity);
		mLikeView = mLayoutInflater.inflate(R.layout.pop_bottle_like, null);
		ImageView iv_unlike = (ImageView) mLikeView
				.findViewById(R.id.iv_unlike);
		ImageView iv_like = (ImageView) mLikeView.findViewById(R.id.iv_like);
		iv_unlike.setOnClickListener(this);
		iv_like.setOnClickListener(this);
		mLikePopview = new CustomPopupWindow(mLikeView,
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		mLikePopview.setBackgroundDrawable(getResources().getDrawable(
				R.drawable.like_frame_right));
		mLikePopview.setOutsideTouchable(true);
		mLikePopview.update();
		mLikePopview.setTouchable(true);
		mLikePopview.setFocusable(true);

	}

	ViewHolder holder;
	BottleEntry bottleEntry;
	public int position;
	View itemView = null;

	private BottleEntry mBottleEntry;

	public void showInfoPopupWindow(View achorView, int btId,
			ViewHolder holder, int position) {
		this.btId = btId;
		this.position = position;
		this.holder = holder;

		if (mLikePopview.isShowing()) {
			mLikePopview.dismiss();
		} else {
			// mLikePopview.showAtLocation(achorView, Gravity.RIGHT, 0, 0);
			mLikePopview.showAsDropDown(achorView, -150, -70);
		}
	}

	public void doOpenBottle(int btId, int position) {
		this.btId = btId;
		this.position = position;
		UICore.eventTask(this, activity, EXEU_OPEN_BOTTLE_OPERATION, "", null);
	}

	public void doDropBottle(int btId, int position) {
		this.btId = btId;
		this.position = position;
		UICore.eventTask(this, activity, EXEU_DROP_BOTTLE_OPERATION, "", null);
	}

	private void dropBottle(int btId) {
		StringBuffer url = new StringBuffer(UrlConfig.discard_bt);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&btid=" + btId);
		ServiceUtils.dout("dropBottle url:" + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("dropBottle result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {
					Message message = handler.obtainMessage(
							EXEU_DROP_BOTTLE_SUCCESS, successmsg);
					handler.sendMessage(message);

				} else {
					Message message = handler.obtainMessage(
							EXEU_DROP_BOTTLE_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void openBottle(int btId) {
		StringBuffer url = new StringBuffer(UrlConfig.open_bt);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&btid=" + btId);
		ServiceUtils.dout("openBottle url:" + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("openBottle result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				if (success == 1) {

					StringBuffer mSingleBottleUrl = new StringBuffer(
							UrlConfig.get_bt_timeline);
					mSingleBottleUrl.append("?clitype=2");
					mSingleBottleUrl.append("&language=" + AppContext.language);
					mSingleBottleUrl.append("&login_uid="
							+ AppContext.getInstance().getLogin_uid());
					mSingleBottleUrl.append("&login_token="
							+ AppContext.getInstance().getLogin_token());
					mSingleBottleUrl.append("&mode=4&btid=" + btId);
					mSingleBottleUrl.append("&feedscount=5");
					ServiceUtils.dout("get open bottle url:"
							+ mSingleBottleUrl.toString());
					String singleResult = HttpUtils.doGet(mSingleBottleUrl
							.toString());
					ServiceUtils.dout("get open bottle results :"
							+ singleResult.toString());

					Gson gson = new Gson();
					BottleTimelineInfo singleBottleInfo = gson.fromJson(
							singleResult, BottleTimelineInfo.class);
					// singleBottleInfo.get
					// BottleEntry mNewBottleEntry =
					// singleBottleInfo.getBts_list().get(0);

					mBottleList.set(position, singleBottleInfo.getBts_list()
							.get(0));

					Message message = handler.obtainMessage(
							EXEU_OPEN_BOTTLE_SUCCESS, successmsg);
					handler.sendMessage(message);
				} else {
					Message message = handler.obtainMessage(
							EXEU_OPEN_BOTTLE_FAILED, errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private void getSingleBottle(int btId) {
		StringBuffer mSingleBottleUrl = new StringBuffer(
				UrlConfig.get_bt_timeline);
		mSingleBottleUrl.append("?clitype=2");
		mSingleBottleUrl.append("&language=" + AppContext.language);
		mSingleBottleUrl.append("&login_uid="
				+ AppContext.getInstance().getLogin_uid());
		mSingleBottleUrl.append("&login_token="
				+ AppContext.getInstance().getLogin_token());
		mSingleBottleUrl.append("&mode=4&btid=" + btId);
		mSingleBottleUrl.append("&likescount=5");
		mSingleBottleUrl.append("&feedscount=5");
		ServiceUtils.dout("getSingleBottle url:" + mSingleBottleUrl.toString());
		String singleResult = null;
		try {
			singleResult = HttpUtils.doGet(mSingleBottleUrl.toString());
			ServiceUtils.dout("getSingleBottle results :"
					+ singleResult.toString());

			Gson gson = new Gson();
			BottleTimelineInfo singleBottleInfo = gson.fromJson(singleResult,
					BottleTimelineInfo.class);
			if (singleBottleInfo.getResults().getAuthok() == 1) {
				mBottleEntry = singleBottleInfo.getBts_list().get(0);
				Message message = handler
						.obtainMessage(EXEU_GET_SINGLE_BOTTLE_SUCCESS);
				handler.sendMessage(message);
			} else {
				Message message = handler.obtainMessage(
						EXEU_GET_TIMELINE_FAILED, singleBottleInfo.getResults()
								.getErrmsg());
				handler.sendMessage(message);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	/**
	 * 喜欢瓶子的操作
	 * 
	 * @param btId
	 *            瓶子ID
	 * @param likeType
	 *            喜欢or不喜欢 <---> 1 or 2
	 */
	private void likeOperation(int btId, int likeType) {
		StringBuffer url = new StringBuffer(UrlConfig.likeop_bt);
		url.append("?clitype=2");
		url.append("&language=" + AppContext.language);
		url.append("&login_uid=" + AppContext.getInstance().getLogin_uid());
		url.append("&login_token=" + AppContext.getInstance().getLogin_token());
		url.append("&btid=" + btId);
		url.append("&liketype=" + likeType);
		ServiceUtils.dout("likeOperation url:" + url.toString());

		try {
			String results = HttpUtils.doGet(url.toString());
			ServiceUtils.dout("likeOperation result:" + results);
			if (null != results) {
				JSONObject obj = new JSONObject(results);
				JSONObject resultObj = obj.getJSONObject("results");
				int success = resultObj.getInt("success");
				String errmsg = resultObj.getString("errmsg");
				String successmsg = resultObj.getString("successmsg");
				Message message = null;
				if (success == 1) {

					switch (likeType) {
					case 1:
						message = handler.obtainMessage(EXEU_LIKE_OPERATION,
								successmsg);
						handler.sendMessage(message);
						break;
					case 2:
						message = handler.obtainMessage(EXEU_UNLIKE_OPERATION,
								successmsg);
						handler.sendMessage(message);
						break;
					default:
						break;
					}
				} else {
					message = handler.obtainMessage(EXEU_LIKE_OPERATION_FAILED,
							errmsg);
					handler.sendMessage(message);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void doMenuItemSelect(int mode) {
		this.mode = mode;
		this.page = 1;
		UICore.eventTask(this, activity, EXEU_GET_MENU_TIMELINE, "", null);
	}

	@Override
	public boolean handleMessage(Message msg) {
		switch (msg.what) {
		case EXEU_GET_TIMELINE:
			setAdapterForThis();
			listView.onRefreshComplete();
			new Thread() {
				public void run() {
					getPushNotice();
				};
			}.start();
			break;
		case EXEU_GET_MORE_TIMELINE:
			mTimeLineAdapter.notifyDataSetChanged();
			// listView.setSelection(visibleLastIndex - visibleItemCount + 1);
			// // 设置选中项
			break;
		case EXEU_DROP_BOTTLE_SUCCESS:
			mBottleList.remove(position);
			mTimeLineAdapter.notifyDataSetChanged();
			String message = (String) msg.obj;
			activity.onToast(message);
			break;
		case EXEU_DROP_BOTTLE_FAILED:
			activity.onToast((String) msg.obj);
			break;
		case EXEU_OPEN_BOTTLE_SUCCESS:
			mTimeLineAdapter.notifyDataSetChanged();
			activity.onToast((String) msg.obj);
			break;
		case EXEU_SET_BTPIC_PAINT:
			activity.onToast((String) msg.obj);
			UICore.eventTask(this, activity, EXEU_GET_SINGLE_BOTTLE_SUCCESS,
					"EXEU_GET_TIMELINE", null);
			break;
		case EXEU_OPEN_BOTTLE_FAILED:
			activity.onToast((String) msg.obj);
			break;
		case EXEU_LIKE_OPERATION:
			activity.onToast((String) msg.obj);
			UICore.eventTask(this, activity, EXEU_GET_SINGLE_BOTTLE_SUCCESS,
					"EXEU_GET_TIMELINE", null);
			break;
		case EXEU_UNLIKE_OPERATION:
			activity.onToast((String) msg.obj);
			UICore.eventTask(this, activity, EXEU_GET_SINGLE_BOTTLE_SUCCESS,
					"EXEU_GET_TIMELINE", null);
			break;
		case EXEU_LIKE_OPERATION_FAILED:
			activity.onToast((String) msg.obj);
			break;
		case EXEU_GET_SINGLE_BOTTLE_SUCCESS:
			mBottleList.set(position, mBottleEntry);
			mTimeLineAdapter.notifyDataSetChanged();
			break;
		case EXEU_SEND_BOTTLE_PRIV_SUCCESS:
			final Bundle bundle = msg.getData();
			try {
				BottleTypeTable table = new BottleTypeTable();
				BottleTypeEntry bottleEntry = table.getBottleType(bundle.getInt("type"));
				int locationSelect = bottleEntry.getBttype_location_select();
				String[] choices = new String[2];
				if (locationSelect > 1) {
					choices[0] = getString(R.string.choose_location_here_throw);
					choices[1] = getString(R.string.choose_location_search_throw);
				} else {
					choices = new String[1];
					choices[0] = getString(R.string.choose_location_here_throw);
				}
				chooseAction(choices, locationSelect , bundle.getInt("type"));
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			break;
		case EXEU_SEND_BOTTLE_PRIV_SUCCESS_NOT_ENABLE:
			activity.onToast((String) msg.obj);
			break;
		case EXEU_SEND_BOTTLE_PRIV_FAILED:
			activity.onToast((String) msg.obj);
			break;
		case EXEU_GET_TIMELINE_FAILED:
			activity.onToast((String) msg.obj);
			break;
		case EXEU_REFRESH_TIMELINE:
			new Thread() {
				public void run() {
					getPushNotice();
				};
			}.start();
			break;
		case EXEU_GET_MORE_TIMELINE_NOTHING:
			activity.onToast(TextUtil.R("no_more_data"));
			loadMoreView.setVisibility(View.GONE);
			mTimeLineAdapter.notifyDataSetChanged();
			// listView.setSelection(visibleLastIndex - visibleItemCount);
			break;
		case throw_bottle_init_location:
//			try {
//				int bottleid = Integer.parseInt(msg.obj.toString());
//				Intent intent2 = new Intent(activity, ThrowBottleSettingActivity.class);
//				intent2.putExtra("bttype_id", bottleid);
//				intent2.putExtra("bt_geo_lng", longitude);
//				intent2.putExtra("bt_geo_lat", latitude);
//				startActivity(intent2);
//			} catch (Exception e) {
//				e.printStackTrace();
//			}
			break;
		case EXEU_PASTERDIR_PAY:
			activity.onToast((String) msg.obj);
			
			break;
		case EXEU_PUSH_NOTICE:
			((HomeActivity) getActivity()).pushNoticeUpdateUI();
			break;
		default:
			break;
		}
		return false;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.iv_send_bottle:
			Intent throwIntent = new Intent(activity,
					ChooseBottleActivity.class);
			throwIntent.putExtra("type", "throw");
			startActivity(throwIntent);
			break;
		case R.id.iv_gain_bottle:
			Intent tryIntent = new Intent(activity, ChooseBottleActivity.class);
			tryIntent.putExtra("type", "try");
			startActivity(tryIntent);
			break;
		case R.id.iv_profile_info:
			Intent settingIntent = new Intent(activity, SettingActivity.class);
			startActivity(settingIntent);
			break;
		case R.id.iv_unlike:// 不喜欢
			mLikePopview.dismiss();
			UICore.eventTask(this, activity, EXEU_UNLIKE_OPERATION, "", null);
			break;
		case R.id.iv_like:// 喜欢
			mLikePopview.dismiss();
			UICore.eventTask(this, activity, EXEU_LIKE_OPERATION, "", null);
			break;
		case R.id.bt_bottle_throw_try:
			Intent throwIntent2 = new Intent(activity, ChooseBottleActivity.class);
			throwIntent2.putExtra("type", "throw");
			startActivity(throwIntent2);
			break;
		case R.id.bt_bottle_gain_try:
			Intent tryIntent2 = new Intent(activity, ChooseBottleActivity.class);
			tryIntent2.putExtra("type", "try");
			startActivity(tryIntent2);
			break;
		case R.id.bt_bottle_profile_try:
			Intent settingIntent2 = new Intent(activity, SettingActivity.class);
			startActivity(settingIntent2);
			break;
		default:
			break;
		}
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		try {
			if (mTimeLineAdapter != null) {
				int itemsLastIndex = mTimeLineAdapter.getCount() + 2; // 数据集最后一项的索引
				int lastIndex = itemsLastIndex + 1; // 加上底部的loadMoreView项 和 head项
				ServiceUtils.dout(TAG + " lastIndex:       " + lastIndex);
				ServiceUtils.dout(TAG + " visibleLastIndex:" + visibleLastIndex);
				if (scrollState == OnScrollListener.SCROLL_STATE_IDLE && visibleLastIndex == lastIndex) {
					// 如果是自动加载,可以在这里放置异步加载数据的代码
					page++;
					loadMoreView.setVisibility(View.VISIBLE);
					UICore.eventTask(this, activity, EXEU_GET_MORE_TIMELINE, null, null);
					Log.i("LOADMORE", "loading...");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem,
			int visibleItemCount, int totalItemCount) {
		listView.setFirstVisiableItem(firstVisibleItem);
		this.visibleItemCount = visibleItemCount;
		visibleLastIndex = firstVisibleItem + visibleItemCount;
	}

	public void doGetBottleInfo() {
		UICore.eventTask(this, activity, EXEU_GET_BOTTLE_INFO, "", null);
	}

	public void initConfig() {
    	String country = getResources().getConfiguration().locale.getCountry();
		if (country.equals("CN")) {
			AppContext.setLanguage(1);
		} else {
			AppContext.setLanguage(0);
		}
    	
    	SharedPreferences preferences = getActivity().getSharedPreferences("Preferences_userinfo", Activity.MODE_APPEND);
    	int login_uid = preferences.getInt("login_uid", 0);
    	String login_token = preferences.getString("login_token", null);
    	AppContext.getInstance().setLogin_uid(login_uid);
		AppContext.getInstance().setLogin_token(login_token);
		if (login_uid == 0 || login_token == null) {
			Intent intent = new Intent(getActivity(), SplashActivity.class);
			getActivity().startActivity(intent);
			getActivity().finish();
		}
    }
	
	private void chooseAction(String[] choices, final int locationSelected, final int bottleId) {
		final Context dialogContext = new ContextThemeWrapper(activity, android.R.style.Theme_Light);
	
		final ListAdapter adapter = new ArrayAdapter<String>(dialogContext,
				android.R.layout.simple_list_item_1, choices);

		final AlertDialog.Builder builder = new AlertDialog.Builder(
				dialogContext);
		builder.setTitle(R.string.system_info);
		builder.setSingleChoiceItems(adapter, -1,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
						if (which == 0) {
							Intent intent2 = new Intent(activity, ThrowBottleSettingActivity.class);
							intent2.putExtra("bttype_id", bottleId);
							intent2.putExtra("bt_geo_lng", AppContext.getInstance().getLongitude());
							intent2.putExtra("bt_geo_lat", AppContext.getInstance().getLatitude());
							startActivity(intent2);
						} else {
							Intent intent = new Intent(activity, ChooseLocationTabsActivity.class);
							intent.putExtra("type", "throw");
							intent.putExtra("bottleId", bottleId);
							intent.putExtra("locationSelect", locationSelected);
							startActivity(intent);
						}
					}
				});
		builder.create().show();
	}
	


	
}
